﻿//     Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;

namespace Microsoft.Gateway.Configuration
{
    public class RulesConfiguration 
    {
        public RulesConfiguration()
        {
            this.Roles = new Dictionary<string, Role>(StringComparer.OrdinalIgnoreCase);
        }

        public IDictionary<string, Role> Roles { get; set; }
        public string Directory { get; set; }
        public string ApplicationName { get; set; }
        [JsonIgnore]
        public IEnumerable<Tuple<string, Role>> OrderedRoles
        {
            get
            {
                return this.Roles
                    .OrderBy(role => role.Value.IsDefaultRole ? 1 : 0)
                    .ThenBy(role => role.Key, StringComparer.OrdinalIgnoreCase)
                    .Select(role => Tuple.Create(role.Key, role.Value));
            }
        }
    }
}
